#include "Utility.h"
#include <iostream>
#include <clocale>
#include <locale>
#include <vector>

Utility::Utility(void)
{
}


Utility::~Utility(void)
{
}

std::string Utility::wstring2string( const std::wstring& ws )
{
	std::setlocale(LC_ALL, "");
	const std::locale locale("");
	typedef std::codecvt<wchar_t, char, std::mbstate_t> converter_type;
	const converter_type& converter = std::use_facet<converter_type>(locale);
	std::vector<char> to(ws.length() * converter.max_length());
	std::mbstate_t state;
	const wchar_t* from_next;
	char* to_next;
	converter.out(state, ws.data(), ws.data() + ws.length(), from_next, &to[0], &to[0] + to.size(), to_next);
	std::string s(&to[0], to_next);

	return s;
}
